
#include "StateGame.h"
#include "StateManager.h"
#include "StateMainMenu.h"
#include "StateEndGame.h"
#include "StatePause.h"
#include "AudioUtils.h"
#include "InputManager.h"
#include "LevelManager.h"
#include "ScoreManager.h"
#include "BackgroundManager.h"

void StateGame::loadContent()
{
    AudioUtils::preloadSfx("FX_Tragar.mp3");
    AudioUtils::preloadSfx("FX_Success.mp3");
    AudioUtils::preloadSfx("FX_Fail.mp3");
    AudioUtils::preloadSfx("FX_Launch2.mp3");
    AudioUtils::preloadSfx("FX_Launch3.mp3");
    AudioUtils::preloadSfx("FX_SuccessComun(score).mp3");
	
	m_ePauseButton = new RenderableEntity("pause", Vector2(50, 890));
    m_ePauseButton->setCentered();
    m_ePauseButton->setupButton(Vector2(1.5f, 1.5f));
    
    LevelManager::instance().init();
    ScoreManager::instance().init();
    BackgroundManager::instance().init();
}

void StateGame::unloadContent()
{
}

void StateGame::enter()
{
    LevelManager::instance().startCountdown();
}

void StateGame::updatePaused(float dt)
{
    BackgroundManager::instance().update(dt);
}

void StateGame::update(float dt)
{
    if(m_ePauseButton->isClicked())
    {
        StateManager::instance().pushState(StatePause::instance());
    }
    else
    {
        LevelManager::instance().update(dt);
		ScoreManager::instance().update(dt);
        
        if(LevelManager::instance().getGameState() == LevelManager::instance().GameOver)
        {
            StateManager::instance().pushState(StateEndGame::instance());
        }
    }
}

void StateGame::render()
{
    BackgroundManager::instance().renderNew();
    // backgrounds firs
    ScoreManager::instance().renderRainbow();
    LevelManager::instance().render();
	ScoreManager::instance().render();
	
	m_ePauseButton->render();
}

void StateGame::exit()
{
}
